<template>
	<div>
		<el-form ref="form" :model="form" :rules="rules" label-width="80px">

			<el-form-item label="类别" prop="category">
				<el-input v-model="form.category"></el-input>
			</el-form-item>

			<el-form-item label="数据代码" prop="dataCode">
				<el-input v-model="form.dataCode"></el-input>
			</el-form-item>

			<el-form-item label="数据名称" prop="dataTime">
				<el-input v-model="form.dataTime"></el-input>
			</el-form-item>

			<el-form-item>
				<el-button type="primary" plain @click="save">保存数据</el-button>
			</el-form-item>
		</el-form>
	</div>
</template>

<script>
	import axios from '@/utils/axiosutils.js';
	export default {
		name: 'DataAdd',
		props: ['editid'],
		components: {},
		data() {
			return {
				form: {
					category: '',
					dataCode: '',
					dataTime: ''
				},
				rules: {
					category: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}],
					dataCode: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}],
					dataTime: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}]
				},
				isupdate: false
			};
		},
		created() {
			if (this.editid) {
				// 如果是修改 用户名输入框禁用
				this.isupdate = true;
				axios.get(
					'/maintain/getById',
					response => {
						this.form.dataId = this.editid;
						this.form.category = response.obj.category;
						this.form.dataCode = response.obj.dataCode;
						this.form.dataTime = response.obj.dataTime;
					}, {
						dataId: this.editid
					}
				);
			}
		},
		methods: {
			save: function() {
				axios.post(
					'/maintain/add',
					resp => {
						this.$emit('update:show', false);
						this.$emit('getData');
					},
					this.form
				);
			}
		}
	};
</script>

<style scoped>
	.el-row {
		height: 60px;
	}
</style>
